import java.util.*;

public class DataManager {
	
	private static ArrayList<Product> products = new ArrayList<Product>();
	private static ArrayList<Order> orders = new ArrayList<Order>();
	private static ArrayList<Customer> customers = new ArrayList<Customer>();

	public DataManager() {
		init();
	}

	public void init() {
		Product p1 = new Product(1, "Big Mac", 7.5, 50);
		Product p2 = new Product(2, "Fillet-O-Fish", 7.4, 50);
		Product p3 = new Product(3, "McSpicy", 8.0, 50);
		Product p4 = new Product(4, "Cheese Burger", 6.5, 50);
		Product p5 = new Product(5, "Samurai Burger", 9.9, 50);

		products.add(p1);
		products.add(p2);
		products.add(p3);
		products.add(p4);
		products.add(p5);


		Customer c1 = new Customer(1, "Kawi", 158, "Lorong 1 Toa Payoh", "#03-03", 319774, "north");
		Customer c2 = new Customer(2, "Kim", 159, "Clemenceau Ave. 1", "#01-01", 418675, "east");
		Customer c3 = new Customer(3, "Clarice", 160, "West Coast Rd", "#02-02", 110656, "west");
		Customer c4 = new Customer(4, "Junming", 161, "Orchard Rd", "#05-04", 576891, "central");
		customers.add(c1);
		customers.add(c2);
		customers.add(c3);
		customers.add(c4);


		ArrayList<Product> op1 = new ArrayList<Product>();	 //op stands for OrderedProducts
		p1.setQty(10);		op1.add(p1);	//first item
		p2.setQty(10);		op1.add(p2);	//second item
		Order o1 = new Order(1, c1, op1);

		ArrayList<Product> op2 = new ArrayList<Product>();	 //op stands for OrderedProducts
		p3.setQty(10);		op2.add(p3);	//first item
		p4.setQty(20);		op2.add(p4);	//second item
		Order o2 = new Order(2, c1, op2);

		ArrayList<Product> op3 = new ArrayList<Product>();	 //op stands for OrderedProducts
		p5.setQty(40);		op3.add(p5);	//first item
		Order o3 = new Order(3, c1, op3);	//second item

		orders.add(o1);
		orders.add(o2);
		orders.add(o3);
	}

	public Order getRandomOrder(){
		Random generator = new Random();
		int orderId = generator.nextInt(4);	//cos there are only 3 orders (0 to 3)

		for (Order o: orders){
			if (o.getId() == orderId){
				return o;
			}
		}

		return null;
	}

	public ArrayList<Order> getAllOrders(){
		return orders;
	}

	public ArrayList<Product> getAllProducts(){
		return products;
	}

	public ArrayList<Customer> getAllCustomers(){
		return customers;
	}

	public Order getOrderById(int oid){
		for (Order o: orders){
			if (o.getId() == oid){
				return o;
			}
		}
		return null;
	}

	public Product getProductById(int pid){
		for (Product p: products){
			if (p.getPid() == pid){
				return p;
			}
		}
		return null;
	}

	public Customer getCustomerById(int cid){
		for (Customer c: customers){
			if (c.getCid() == cid){
				return c;
			}
		}
		return null;
	}

	public void save(){
		//for saving to database when needed
	}
}